package com.atguigu.demo;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchDemo {

    /**
     * 六个同学下课，班长锁门，只有六个同学走完之后就锁门
     *
     * @param args
     */
    public static void main(String[] args) throws InterruptedException {

        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "号，同学走了");
                countDownLatch.countDown();
            }, String.valueOf(i)).start();
        }

        countDownLatch.await();
        System.out.println("班长锁门，走人。");
    }

}
